<?php

class Application_Model_User
{
    protected $_updated;
    protected $_name;
    protected $_firstname;
    protected $_email;
    protected $_login;
    protected $_password;
    protected $_id;
 
    public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }
 
    public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        $this->$method($value);
    }
 
    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        return $this->$method();
    }
 
    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }
 
    public function setName($name)
    {
        $this->_name = (string) $name;
        return $this;
    }
 
    public function getName()
    {
        return $this->_name;
    }
 
    public function setFirstname($firstname)
    {
        $this->_firstname = (string) $firstname;
        return $this;
    }
 
    public function getFirstname()
    {
        return $this->_firstname;
    }
 
    public function setEmail($email)
    {
        $this->_email = (string) $email;
        return $this;
    }
 
    public function getEmail()
    {
        return $this->_email;
    }
 
    public function setLogin($login)
    {
        $this->_login = (string) $login;
        return $this;
    }
 
    public function getLogin()
    {
        return $this->_login;
    }
 
    public function setPassword($pwd)
    {
        //$this->_password = (string) sha1($pwd);
        $this->_password = (string) $pwd;
        return $this;
    }
 
    public function getPassword()
    {
        return $this->_password;
    }
 
    public function setUpdated($ts)
    {
        $this->_updated = $ts;
        return $this;
    }
 
    public function getUpdaed()
    {
        return $this->_updated;
    }
 
    public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }
 
    public function getId()
    {
        return $this->_id;
    }
 
    public function getAttribute($key)
    {
        switch($key)
        {
            case 'name':
                return $this->_name;
                break;
            case 'firstname':
                return $this->_firstname;
                break;
            case 'email':
                return $this->_email;
                break;
            case 'login':
                return $this->_login;
                break;
            case 'password':
                return $this->_password;
                break;
            case 'id':
                return $this->_id;
                break;
            default:
                return $this->_id;
                break;
        }
    }
 
    public function setAttribute($key,$value)
    {
        switch($key)
        {
            case 'name':
                $this->_name = (string) $value;
                break;
            case 'firstname':
                $this->_firstname = (string) $value;
                break;
            case 'email':
                $this->_email = (string) $value;
                break;
            case 'login':
                $this->_login = (string) $value;
                break;
            case 'password':
                //$this->_password = (string) sha1($value);
                $this->_password = (string) $value;
                break;
            case 'id':
                $this->_id = (int) $id;
                break;
            default:
                $this->_id = (int) $id;
                break;
        }
    }
}

